package ACM.ZhongAn;

import java.util.Scanner;

/**
 * @author way
 * @create 2025-04-10 19:54
 */
public class _0410_2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        sc.nextLine(); // 跳过行尾换行符

        char[][] matrix = new char[n][];
        for (int i = 0; i < n; i++) {
            matrix[i] = sc.nextLine().trim().toCharArray();
        }

        while (q-- > 0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();

            // 转换为0-based坐标
            int currentRow = b - 1;
            int currentCol = c - 1;

            // 计算原始位置
            int deltaRow = (currentCol + a) / m;
            int originalRow = (currentRow + deltaRow) % n;
            originalRow = (originalRow % n + n) % n; // 处理负数情况
            int originalCol = (currentCol + a) % m;

            System.out.println(matrix[originalRow][originalCol]);
        }
        sc.close();
    }
}
